
public class p1010_110ms_1st {

	public static//
	// -----
	// -----
	class Main {
		public static void main(String[] args) throws Exception {
			java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
			String line;
			while ((line = reader.readLine()) != null) {
				types = parseInts(line);
				java.util.Arrays.sort(types);
				for (int customer : parseInts(reader.readLine()))
					process(types, customer);
			}
		}

		static int[] parseInts(String line) {
			String[] parts = line.split(" ");
			int[] nums = new int[parts.length - 1];
			for (int i = 0; i < nums.length; i++)
				nums[i] = Integer.parseInt(parts[i]);
			return nums;
		}

		static void process(int[] types, int customer) {
			sol = null;
			int[] cache = new int[maxBit];
			process2(cache, 0, customer, types.length - 1, types[types.length - 1]);
			print(customer);
		}

		static final int maxBit = 4;
		static int[] types;

		static void process2(int[] cache, int cached, int leftVal, int maxType, int maxTypeVal) {
			if (leftVal == 0) {
				int[] sol = new int[cached];
				System.arraycopy(cache, 0, sol, 0, cached);
				save(sol);
				return;
			}
			if (leftVal < 0 || leftVal > maxTypeVal * (maxBit - cached)) {
				return;
			}
			for (int type = maxType; type >= 0; type--) {
				int val = types[type];
				cache[cached] = type;
				process2(cache, cached + 1, leftVal - val, type, val);
			}
		}

		static int[] sol;
		static int solType;
		static int solType2;
		static boolean solTie;

		static void save(int[] sol2) {
			int ret = compare(sol2);
			if (ret > 0) {
				sol = sol2;
				solType = solType2;
				solTie = false;
			} else if (ret == 0) {
				solTie = true;
			}
		}

		static int compare(int[] sol2) {
			solType2 = 1;
			for (int i = 1; i < sol2.length; i++)
				if (sol2[i] != sol2[i - 1])
					solType2++;
			if (sol == null)
				return 1;
			// max types
			if (solType > solType2)
				return -1;
			if (solType < solType2)
				return 1;
			// total stamps
			if (sol.length < sol2.length)
				return -1;
			if (sol.length > sol2.length)
				return 1;
			// highest single-value
			int max1 = types[sol[0]];
			int max2 = types[sol2[0]];
			if (max1 > max2)
				return -1;
			if (max1 < max2)
				return 1;
			return 0;
		}

		static void print(int customer) {
			System.out.print(customer + " ");
			if (sol == null) {
				System.out.println("---- none");
			} else {
				System.out.print("(" + solType + "): ");
				if (solTie) {
					System.out.println("tie");
				} else {
					for (int i = 0; i < sol.length; i++)
						sol[i] = types[sol[i]];
					java.util.Arrays.sort(sol);
					for (int i = 0; i < sol.length - 1; i++) {
						System.out.print(sol[i] + " ");
					}
					System.out.println(sol[sol.length - 1]);
				}
			}
		}
	}

	// -----
	// -----

	public static void main(String[] args) throws Exception {
		Judge.run();
	}

}
